import { takeStores, press, sleep } from "../scrapbox-userscript-std/dom.ts"; const callback = (e: CompositionEvent) => { if (!e.isTrusted) return; if (e.data.length === 0) return; if (!(e.target instanceof HTMLTextAreaElement)) return; if (e.target.id !== "text-input") return; const { cursor, selection } = takeStores(); if (!selection.hasSingleLineSelection()) return; switch([...e.data].pop()){ case "「": { const button = document.getElementsByClassName('button link-button')?.[0] if (!(button instanceof HTMLElement)) return; //e.preventDefault(); //e.stopPropagation(); button.click(); const textarea = e.target; (async () => { await sleep(100); textarea.blur(); await new Promise((resolve) => { document.addEventListener("compositionend", resolve, { capture: true, once: true }); }); press("Backspace"); textarea.focus(); cursor.focus(); })(); break; } default: break; } }; export const setup = (): () => void => { document.addEventListener("compositionupdate", callback, { capture: true }); return () => { document.removeEventListener("compositionupdate", callback, { capture: true }); }; };